package com.lanou.zhihu.web.controller;

import com.lanou.zhihu.entity.Answer;
import com.lanou.zhihu.entity.Question;
import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.service.Attention_issue_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/attention")
public class Attention_Issue_Controller {
    @Autowired
    public Attention_issue_Service attentionIssueService;

    @ResponseBody
    @RequestMapping("/attentionIssue")//关注的问题
    public Integer attentionIssue(HttpServletRequest request) {
        User user1 = (User) request.getSession().getAttribute("user");
        int u = attentionIssueService.findAttention(user1.getId());
        return u;
    }

    @ResponseBody
    @RequestMapping("/userAnswer")//用户的回答的总条数
    public Integer userAnswer(HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        int a = attentionIssueService.findAnswer(user.getId());
        return a;
    }

    @ResponseBody
    @RequestMapping("/userAnswers")//用户的所有回答
    public Map<String, Object> userAnswers(HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        List<Answer> answer = attentionIssueService.findUserIssue(user.getId());
        Map<String, Object> map = new HashMap<>();
        map.put("msg", answer);
        return map;
    }

    @ResponseBody
    @RequestMapping("/userQuiz")//用户提问
    public List<Question> userQuiz(HttpServletRequest request) {
        User user = (User) request.getSession().getAttribute("user");
        List<Question> a = attentionIssueService.userQuiz(user.getId());
        return a;
    }
}
